const {
  DataTypes
} = require('sequelize');

module.exports = sequelize => {
  const attributes = {
    id: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: null,
      comment: "ID",
      primaryKey: true,
      field: "id",
      autoIncrement: true
    },
    menuId: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: null,
      comment: "关联的菜单ID",
      primaryKey: false,
      field: "menu_id",
      autoIncrement: false
    },
    layerName: {
      type: DataTypes.CHAR,
      allowNull: false,
      defaultValue: null,
      comment: "图层名称",
      primaryKey: false,
      field: "layer_name",
      autoIncrement: false
    },
    layerType: {
      type: DataTypes.CHAR,
      allowNull: false,
      defaultValue: null,
      comment: "图层类型（如：WMS、WFS、Vector等）",
      primaryKey: false,
      field: "layer_type",
      autoIncrement: false
    },
    layerUrl: {
      type: DataTypes.CHAR,
      allowNull: false,
      defaultValue: null,
      comment: "图层服务地址",
      primaryKey: false,
      field: "layer_url",
      autoIncrement: false
    },
    layerStyle: {
      type: DataTypes.JSON,
      allowNull: true,
      defaultValue: null,
      comment: "图层样式配置",
      primaryKey: false,
      field: "layer_style",
      autoIncrement: false
    },
    layerParams: {
      type: DataTypes.JSON,
      allowNull: true,
      defaultValue: null,
      comment: "图层参数配置",
      primaryKey: false,
      field: "layer_params",
      autoIncrement: false
    },
    isVisible: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: "是否可见（1-是 0-否）",
      primaryKey: false,
      field: "is_visible",
      autoIncrement: false
    },
    orderNum: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "显示顺序",
      primaryKey: false,
      field: "order_num",
      autoIncrement: false
    },
    status: {
      type: DataTypes.CHAR,
      allowNull: false,
      defaultValue: "0",
      comment: "状态（0正常 1停用）",
      primaryKey: false,
      field: "status",
      autoIncrement: false
    },
    delFlag: {
      type: DataTypes.CHAR,
      allowNull: false,
      defaultValue: "0",
      comment: "删除标志（0代表存在 2代表删除）",
      primaryKey: false,
      field: "del_flag",
      autoIncrement: false
    },
    createBy: {
      type: DataTypes.CHAR,
      allowNull: false,
      defaultValue: "",
      comment: "创建者",
      primaryKey: false,
      field: "create_by",
      autoIncrement: false
    },
    createTime: {
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: null,
      comment: "创建时间",
      primaryKey: false,
      field: "create_time",
      autoIncrement: false
    },
    updateBy: {
      type: DataTypes.CHAR,
      allowNull: false,
      defaultValue: "",
      comment: "更新者",
      primaryKey: false,
      field: "update_by",
      autoIncrement: false
    },
    updateTime: {
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: null,
      comment: "更新时间",
      primaryKey: false,
      field: "update_time",
      autoIncrement: false
    },
    remark: {
      type: DataTypes.CHAR,
      allowNull: true,
      defaultValue: null,
      comment: "备注",
      primaryKey: false,
      field: "remark",
      autoIncrement: false
    }
  };
  const options = {
    tableName: "sys_layer",
    comment: "",
    indexes: []
  };
  const SysLayerModel = sequelize.define("sys_layer_model", attributes, options);

  SysLayerModel.associate = function(models) {
    // 与菜单表建立关联
    SysLayerModel.belongsTo(models.sys_menu_model, {
      foreignKey: 'menu_id',
      targetKey: 'id'
    });
  };

  return SysLayerModel;
}; 